Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove octal literals misfeature #417

Merged
merged 1 commit into from
Feb 20, 2012
Merged

Remove octal literals misfeature #417

merged 1 commit into from
Feb 20, 2012

Conversation

fehrenbach
Copy link
Contributor

Currently Julia has octal integer literals, like this:
julia> 010 8

Since they are not mentioned in the manual (as opposed to hex literals) I assume they are an accident, inherited from femtolisp's one-argument string->number implementation.

So here's my try at fixing this.

@StefanKarpinski
Copy link
Member

Woah. I was not aware of that. @JeffBezanson, were you?

StefanKarpinski added a commit that referenced this pull request Feb 20, 2012
Remove octal literals misfeature
@StefanKarpinski StefanKarpinski merged commit 82711d7 into JuliaLang:master Feb 20, 2012
@StefanKarpinski
Copy link
Member

Btw, while we're on the subject, how do you feel about hex literals for unsigned ints? Feature or misfeature?

@JeffBezanson
Copy link
Member

Do we genuinely not want octal literals? Is there something bad about them? Doesn't matter to me much either way, just curious if this is a real problem somehow.

@fehrenbach
Copy link
Contributor Author

They're probably not a real problem.
But most people don't expect to have their numbers behave differently because of leading zeroes and I assume nobody would miss octal literals.
R and Matlab don't have them, and besides calculating file access privileges, I don't think there is any use case for them.
Following the principle of least surprise I'd like to see them removed.

Re: hex
Honestly, I don't care much :) I rarely use hex literals, but they come in handy for the occasional bit twiddling.
More importantly, they are easy to distinguish visually, and are unlikely to be entered unknowingly.

@JeffBezanson
Copy link
Member

Ok, I agree with that. Better to err on the side of fewer features. And if you really want octal parse_oct("377") works.

@jckarter
Copy link

You might try a more explicit prefix for octal such as 0o. The leading zero is a weird C-ism that catches people not familiar with C off-guard, and octal doesn't really come up much in modern programming.

@jckarter
Copy link

Re: hex, having hexadecimal floating-point syntax would be nice too. Hex floats are useful for precisely reading and writing float values as text.

@nolta
Copy link
Member

nolta commented Oct 20, 2012

Octal literals might be useful for functions which set filesystem permissions, e.g., chmod(path, 0755).

@johnmyleswhite
Copy link
Member

I agree that having octal literals could be useful if we were using a better prefix like 0o.

@StefanKarpinski
Copy link
Member

0o775 is pretty weird looking, but is better IMO than the dreaded 0755 traditional.

@nolta
Copy link
Member

nolta commented Oct 20, 2012

python3 decided to use 0o, while perl6 decided on 0c.

I think i'll go ahead and add 0o literals.

@JeffBezanson
Copy link
Member

0o is certainly consistent with 0x and 0b. It's amusing how the only use of this is file permissions.

@StefanKarpinski
Copy link
Member

We could also just interpret the decimal value 755 as though it were octal when passing integers as permission masks.

@staticfloat
Copy link
Member

We could also just interpret the decimal value 755 as though it were octal when passing integers as permission masks.

I like this, but I feel it also breaks away from most other programming language implementations. I know Python and C are both octal-based, are there any examples of programming languages that use decimal permissions? (If only there were a way to auto-detect and give the best of both worlds. :P )

@StefanKarpinski
Copy link
Member

Interpreting decimal values as though they were octal also has the issue that bitwise operations don't work right:

julia> 755 & 666
658

julia> oct(0o755 & 0o666)
"644"

@staticfloat
Copy link
Member

Oof, yeah, that's a killer. I, personally, would expect bitwise operations to work when it comes to file permissions. Perhaps we should just let this one be, and make notes in the documentation that permissions should be passed as 0o755 literals, etc...

@kbara
Copy link

kbara commented Nov 26, 2013

This is still a problem with BigInt, when it's given a string argument:

julia> BigInt(033)
33 # works as expected
julia> BigInt("033")
27 # doesn't; it was interpreted as octal.

@StefanKarpinski
Copy link
Member

Oh, that's not good at all. Thanks for point it out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants